<template>
  <TreeSelect
    v-model="rvalue"
    :filterable="true"
    :options="options"
    v-bind="$attrs"
    :props="{
      value: 'value',
      label: 'label',
      children: 'children'
    }"
  ></TreeSelect>
</template>

<script>
import { mapGetters } from 'vuex';
import TreeSelect from '@/components/TreeSelect';
import { list } from '@/api/elevator-emer-fault/emerFaultInfo/index';
export default {
  name: 'FaultTypeSelect',
  components: {
    TreeSelect
  },
  props: {
    value: {}
  },
  data() {
    return {
      options: []
    };
  },
  computed: {
    ...mapGetters(['dictionary', 'dictionaryArr']),
    rvalue: {
      get() {
        return this.value;
      },
      set(v) {
        this.$emit('input', v);
      }
    }
  },
  created() {
    list().then(({ rows }) => {
      this.options = this.dictionaryArr.emer_fault_type.map(i=>({...i}));
      for (const row of rows) {
        for (const option of this.options) {
          if (row.faultType == option.value) {
            row.label = row.faultName;
            row.value = row.emerFaultId;

            if (!option.children) {
              option.children = [row];
            } else {
              option.children.push(row);
            }
          }
        }
      }
    });
  }
};
</script>
<style lang="scss" scoped></style>
